<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="incidente" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{incidenteHome.managed ? 'Edit' : 'Add'} Incidente</f:facet>




            <s:decorate id="dataField" template="layout/edit.xhtml">
                <ui:define name="label">Data</ui:define>
                <h:inputText id="data"
                          value="#{incidenteHome.instance.data}">
                    <a:support event="onblur" reRender="dataField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="descricaoField" template="layout/edit.xhtml">
                <ui:define name="label">Descricao</ui:define>
                <h:inputTextarea id="descricao"
                               cols="80"
                               rows="3"
                              value="#{incidenteHome.instance.descricao}"/>
            </s:decorate>


            <s:decorate id="prioridadeField" template="layout/edit.xhtml">
                <ui:define name="label">Prioridade</ui:define>
                <h:inputText id="prioridade"
                       required="true"
                          value="#{incidenteHome.instance.prioridade}">
                    <a:support event="onblur" reRender="prioridadeField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>



            <s:decorate id="statusField" template="layout/edit.xhtml">
                <ui:define name="label">Status</ui:define>
                <h:inputText id="status"
                       required="true"
                          value="#{incidenteHome.instance.status}">
                    <a:support event="onblur" reRender="statusField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>

            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{incidenteHome.persist}"
                       disabled="#{!incidenteHome.wired}"
                       rendered="#{!incidenteHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{incidenteHome.update}"
                       rendered="#{incidenteHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{incidenteHome.remove}"
                      immediate="true"
                       rendered="#{incidenteHome.managed}"/>

            <s:button id="done"
                   value="Done"
             propagation="end"
                    view="/Incidente.xhtml"
                rendered="#{incidenteHome.managed}"/>

            <s:button id="cancel"
                   value="Cancel"
             propagation="end"
                    view="/#{empty incidenteFrom ? 'IncidenteList' : incidenteFrom}.xhtml"
                rendered="#{!incidenteHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Criador">
    <div class="association" id="criadorParent">

        <h:outputText value="There is no criador associated with this incidente."
                   rendered="#{incidenteHome.instance.criador == null}"/>

        <rich:dataTable var="_usuario"
                   value="#{incidenteHome.instance.criador}"
                rendered="#{incidenteHome.instance.criador != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="criadorTable">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_usuario.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Login</f:facet>
                <h:outputText value="#{_usuario.login}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Tipo</f:facet>
                <h:outputText value="#{_usuario.tipo}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button value="#{incidenteHome.instance.criador != null ? 'Change' : 'Select'} criador"
                       view="/UsuarioList.xhtml">
                <f:param name="from" value="IncidenteEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Respostas">
        <h:form styleClass="association" id="respostasChildren">

            <h:outputText value="There are no respostas associated with this incidente."
                       rendered="#{empty incidenteHome.respostas}"/>

            <rich:dataTable value="#{incidenteHome.respostas}"
                           var="_resposta"
                      rendered="#{not empty incidenteHome.respostas}"
                    rowClasses="rvgRowOne,rvgRowTwo"
                            id="respostasTable">
                <rich:column sortBy="#{_resposta.id}">
                    <f:facet name="header">Id</f:facet>
                    <h:outputText value="#{_resposta.id}"/>
                </rich:column>
                <rich:column sortBy="#{_resposta.data}">
                    <f:facet name="header">Data</f:facet>
                    <h:outputText value="#{_resposta.data}"/>
                </rich:column>
                <rich:column sortBy="#{_resposta.texto}">
                    <f:facet name="header">Texto</f:facet>
                    <h:outputText value="#{_resposta.texto}"/>
                </rich:column>
            </rich:dataTable>

        </h:form>

        <f:subview rendered="#{incidenteHome.managed}" id="respostas">
        <div class="actionButtons">
            <s:button id="addresposta"
                   value="Add resposta"
                    view="/RespostaEdit.xhtml"
             propagation="none">
                 <f:param name="incidenteId"
                         value="#{incidenteHome.instance.id}"/>
                 <f:param name="respostaFrom" value="Incidente"/>
            </s:button>
        </div>
        </f:subview>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
